package com.ruoyi.school.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.school.domain.MajorGrade;
import com.ruoyi.school.service.IMajorGradeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分数线Controller
 * 
 * @author ruoyi
 * @date 2024-01-25
 */
@RestController
@RequestMapping("/school/school_grade")
public class MajorGradeController extends BaseController
{
    @Autowired
    private IMajorGradeService majorGradeService;

    /**
     * 查询分数线列表
     */
    @PreAuthorize("@ss.hasPermi('school:school_grade:list')")
    @GetMapping("/list")
    public TableDataInfo list(MajorGrade majorGrade)
    {
        startPage();
        List<MajorGrade> list = majorGradeService.selectMajorGradeList(majorGrade);
        return getDataTable(list);
    }

    /**
     * 导出分数线列表
     */
    @PreAuthorize("@ss.hasPermi('school:school_grade:export')")
    @Log(title = "分数线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MajorGrade majorGrade)
    {
        List<MajorGrade> list = majorGradeService.selectMajorGradeList(majorGrade);
        ExcelUtil<MajorGrade> util = new ExcelUtil<MajorGrade>(MajorGrade.class);
        util.exportExcel(response, list, "分数线数据");
    }

    /**
     * 获取分数线详细信息
     */
    @PreAuthorize("@ss.hasPermi('school:school_grade:query')")
    @GetMapping(value = "/{gradeId}")
    public AjaxResult getInfo(@PathVariable("gradeId") Long gradeId)
    {
        return success(majorGradeService.selectMajorGradeByGradeId(gradeId));
    }

    /**
     * 新增分数线
     */
    @PreAuthorize("@ss.hasPermi('school:school_grade:add')")
    @Log(title = "分数线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MajorGrade majorGrade)
    {
        return toAjax(majorGradeService.insertMajorGrade(majorGrade));
    }

    /**
     * 修改分数线
     */
    @PreAuthorize("@ss.hasPermi('school:school_grade:edit')")
    @Log(title = "分数线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MajorGrade majorGrade)
    {
        return toAjax(majorGradeService.updateMajorGrade(majorGrade));
    }

    /**
     * 删除分数线
     */
    @PreAuthorize("@ss.hasPermi('school:school_grade:remove')")
    @Log(title = "分数线", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gradeIds}")
    public AjaxResult remove(@PathVariable Long[] gradeIds)
    {
        return toAjax(majorGradeService.deleteMajorGradeByGradeIds(gradeIds));
    }
}
